package features.advance.ch3;

import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.util.Scanner;

public class SocketTest {
    public static void main(String[] args) throws IOException {
        Socket socket = null;
        try{
            String url = "time-A.timefreq.bldrdoc.gov";
            url = "www.baidu.com";
            int port = 80;
            socket = new Socket(url, port);
            InputStream inputStream = socket.getInputStream();
            Scanner scanner = new Scanner(inputStream);
            while (scanner.hasNext()){
                String s = scanner.nextLine();
                System.out.println(s);
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(socket != null){
                socket.close();
            }
        }
    }
}
